
package com.hmsg.health.dao;

import com.hmsg.health.bean.domain.UserAccountDo;
import com.hmsg.health.bean.domain.UserAccountRecordDo;
import com.hmsg.health.bean.domain.UserDo;
import com.hmsg.health.bean.domain.UserTaskDo;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserAccountRecordDao {
    @Select("select * from s_account_record where id=#{id}")
    UserAccountRecordDo findOne(@Param("id")Integer id);
    
   
  
    @Insert("<script>" +
    "insert into `s_account_record` " +
    "  <set>" +
    "    <if test='info.userId != null'>" +
    "     `user_id` = #{info.userId}, " +
    "    </if>" +
    "    <if test='info.glodType != null'>" +
    "      `glod_type` = #{info.glodType}, " +
    "    </if>" +
    "    <if test='info.type != null'>" +
    "      `type` = #{info.type}, " +
    "    </if>" +
    "    <if test='info.amount != null'>" +
    "      `amount` = #{info.amount}, " +
    "    </if>" +
    "    <if test='info.title != null'>" +
    "      `title` = #{info.title}, " +
    "    </if>" +
    "    <if test='info.createTime != null'>" +
    "      `create_time` = #{info.createTime} " +
    "    </if>" +
 
   
    "  </set>" +
    "</script>")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	int save(@Param("info") UserAccountRecordDo info);

    @Select("<script>" +
    	    "select * from  `s_account_record` where 1=1 " +
    	    "    <if test='info.id != null'>" +
    	    "     and `id` = #{info.id} " +
    	    "    </if>" +
    	    "    <if test='info.type != null'>" +
    	    "    and  `type` = #{info.type} " +
    	    "    </if>" +
    	    "    <if test='info.userId != null'>" +
    	    "    and  `user_id` = #{info.userId} " +
    	    "    </if>" +
    	    "    <if test='info.glodType != null'>" +
    	    "      and glod_type  = #{info.glodType} " +
    	    "    </if>" +
    	    
    	   "    <if test='info.time != null '>" +
    	   "   and  DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(#{info.time},'%Y-%m-%d') " +
    	   "    </if>" +
    	    "    order by id desc" +
    	    "    <if test='info.startNo != null'>" +
    	    "      limit #{info.startNo},#{info.pageSize}" +
    	    "    </if>" +
    	    "</script>")
   
    List<UserAccountRecordDo> select(@Param("info") UserAccountRecordDo info);

    @Update({"<script>",
		"UPDATE  s_user_account",
			"<trim prefix='set' suffixOverrides=','>",
		
		"<if test='user.glod!=null'>",
		"glod= #{user.glod},",
		"</if>",
		"<if test='user.canWithdraw!=null'>",
		"can_withdraw= #{user.canWithdraw},",
		"</if>",
		"<if test='user.score!=null'>",
		"score= #{user.score}",
		"</if>",
	
		"</trim>",
		"where id = #{user.id}",
		"</script>"})
 	Integer update(@Param("user") UserAccountDo user);

   
}